# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Alex Yam <alex@alexyam.com>
pkgname=pulsar-client-cpp
pkgver=2.10.1
pkgrel=0
pkgdesc="Apache Pulsar C++ client"
url="https://pulsar.apache.org/docs/en/client-libraries-cpp/"
arch="all"
#    Apache-2.0	: pulsar
#  BSD-2-Clause	: pulsar-client-cpp/lib/lz4/lz4.{h,c}
# 	   Zlib	: pulsar-client-cpp/lib/checksum/crc32c_sw.cc
license="Apache-2.0 AND BSD-2-Clause AND Zlib"
subpackages="$pkgname-static $pkgname-dev py3-pulsar-client-cpp:_py3"
options="!check" # test requires docker/java/pulsar-server
depends_dev="$pkgname"
makedepends="
	boost-dev
	cmake
	curl-dev
	openssl-dev
	protobuf-dev
	py3-setuptools
	python3-dev
	samurai
	snappy-dev
	zstd-dev
	"
source="apache-pulsar-$pkgver-src.tar.gz::https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=pulsar/pulsar-$pkgver/apache-pulsar-$pkgver-src.tar.gz"
builddir="$srcdir/apache-pulsar-$pkgver-src/pulsar-client-cpp"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_SKIP_BUILD_RPATH=true \
		-DBUILD_DYNAMIC_LIB=ON \
		-DBUILD_PERF_TOOLS=OFF \
		-DBUILD_PYTHON_WRAPPER=ON \
		-DBUILD_STATIC_LIB=ON \
		-DBUILD_TESTS=OFF \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

_py3() {
	pkgdesc="Python bindings for Apache Pulsar C++ client"
	depends="python3"
	cd "$builddir"/python
	mv ../build/python/_pulsar.so .
	python3 setup.py install --prefix=/usr --root="$subpkgdir"
}

sha512sums="
19c078f65b9105728adda3926a9a1527d6498f0e2337d37497a6d965a38acf94e217e58939bc5b0a8b8166511ae9ee176ee3d0c764d4777e285b7bcaeb2731e1  apache-pulsar-2.10.1-src.tar.gz
"
